<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>新增地址</title>
    <link href="../css.min/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../css/header.css" />
    <link rel="stylesheet" href="../css/common.css" />
    <style>
    	.mui-input-row label {
				padding: 12px 0 12px 15px;
				width: 38%;
			}
			.mui-input-row label~input,
			.mui-input-row label~textarea {
				width: 62%;
				float: left;
			}
			.mui-input-row label,
			.mui-input-row input,
			.mui-input-row textarea {
				font-size: 15px;
			}
			#region_id ~ span,
			#contact-address ~ span {
				position: absolute;
				right: 7px;
				top: 7px;
				color: #999;
				width: 30px;
				text-align: right;
			}
			.mui-bar .mui-btn.mui-pull-right {
				margin-left: 0;
				margin-right: 0;
			}
			.mui-input-group.mui-inline {
				display: table;
			}
			.mui-input-group.mui-inline:before,
			.mui-input-group.mui-inline:after {
				height: 0;
			}
			.mui-input-group.mui-inline .mui-input-row {
				display: table-cell;
				width: 100%;
				vertical-align: middle;
				background-color: #fff;
			}
			.mui-input-group.mui-inline .mui-input-row:after {
				height: 0;
			}
			.mui-input-group.mui-inline .mui-input-row input[type=number] {
				margin-bottom: 0;
			}
			.mui-input-group.mui-inline .mui-button-row {
				padding: 0;
				display: table-cell;
				width: 1%;
				white-space: nowrap;
				vertical-align: middle;
			}
			.mui-input-group.mui-inline .mui-button-row button {
				padding: 9px 12px;
				margin-left: 5px;
			}
    </style>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">新增地址</h1>
	    <button id="save" type="button" class="mui-right mui-btn  mui-btn-link mui-btn-nav mui-pull-right">
			保存
		</button>
	</header>
	<div class="mui-content">
		<div class="mui-input-group" style="margin-top: 0px;">
				<div class="mui-input-row">
					<label>您的真实姓名</label>
					<input id="contact-name" placeholder="请填写您的真实姓名（必填）" class="mui-input-clear" type="text">
				</div>
				<div class="mui-input-row">
					<label>您的手机号</label>
					<input id="contact-phone" placeholder="请填写您的手机号码（必填）" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" class="mui-input-clear" type="tel">
				</div>
				<div class="mui-input-row" style="height: 80px;">
					<label>详细地址</label>
					<textarea id="contact-address" placeholder="请填写您的详细地址（必填）" style="height: 80px;padding-right: 30px;"></textarea>
					<span id="geolocation" class="mui-icon mui-icon-location"></span>
				</div>
		</div>
	</div>
</body>
<script src="../js.min/mui.min.js"></script>
<script type="text/javascript" src="../js/config.js" ></script>
<script type="text/javascript" src="../js/utils.js" ></script>
<script type="text/javascript" src="../js/cache.js" ></script>
<script type="text/javascript" charset="utf-8">
    mui.init();
    
    var Name_Input=null,Phone_Input=null,Address_Input=null,SaveBtn=null;
    document.addEventListener("DOMContentLoaded",function(){
    	Name_Input=document.getElementById("contact-name");
    	Phone_Input=document.getElementById("contact-phone");
    	Address_Input=document.getElementById("contact-address");
    	SaveBtn=document.getElementById("save");
    	
    	//保存地址
    	SaveBtn.addEventListener('tap',function(){
    		if(CACHE.Login()=="true" && CACHE.UserName()){
    			var u=Name_Input.value.trim();
    			var p=Phone_Input.value.trim();
    			var a=Address_Input.value.trim();
    			
    			var e=this;
    			
    			if(u.length<1) return mui.toast("请填写真实姓名");
    			if(p.length<1) return mui.toast("请填写手机号");
    			if(a.length<1) return mui.toast("请填写详细地址");
    			
    			e.wa=plus.nativeUI.showWaiting("请稍后...");
    			mui.ajax_query("createContact!PPH",
    			{userName:CACHE.UserName(),contactName:u,
    			contactPhone:p,contactAddress:a},
    			function(d){
    				e.wa.close();
    				if(!d) return mui.alert("新增地址出错");
    				
    				if(d["code"]==1){
    					mui.fire(plus.webview.currentWebview().opener(),"RefreshPage");
    					setTimeout(function(){plus.webview.currentWebview().close()},1000);
    				}else{
    					mui.alert(d["msg"]);
    				}
    				
    			},
    			function(c,m){
    				e.wa.close();
    				mui.alert("新增地址失败");
    			});
    			
    		}else{
    			utils.openWindow("login","login.html","slide-in-right",300,false);
    		}
    	});
    	
    },false);
    
</script>
</html>